package com.sky.rabc.controller;

import com.sky.rabc.config.JsonResult;
import com.sky.rabc.dto.AddNewBackRoleDTO;
import com.sky.rabc.dto.AddNewBackUserDTO;
import com.sky.rabc.dto.UpdateBackRoleDTO;
import com.sky.rabc.mapper.BackRoleMapper;
import com.sky.rabc.service.BackRoleService;
import com.sky.rabc.service.impl.BackRoleServiceImpl;
import com.sky.rabc.utils.PageData;
import com.sky.rabc.vo.BackRoleListItemVO;
import com.sky.rabc.vo.BackRoleVO;
import jakarta.annotation.Resource;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

/**
 * 后台角色相关接口
 *
 * @author 刘泓君
 * @className BackRoleController
 * @description 后台角色相关接口
 * @date 2024/6/20
 */
@RestController
@RequestMapping("back-role")
public class BackRoleController {
    @Resource
    private BackRoleServiceImpl backRoleService;
    @PostMapping("/add-new")
    public JsonResult<Void> AddNew(@RequestBody AddNewBackRoleDTO addNewBackRoleDTO) {
        backRoleService.addNew(addNewBackRoleDTO);
        return JsonResult.ok();
    }
    @PostMapping("/update")
    public JsonResult<Void> updateRole(@RequestBody UpdateBackRoleDTO updateBackRoleDTO){
        backRoleService.update(updateBackRoleDTO);
        return JsonResult.ok();
    }
    @DeleteMapping("/delete/{id:[0-9]+}")
    public JsonResult<Void> deleteById(@PathVariable Long id){
        backRoleService.delRoleById(id);
        return JsonResult.ok();
    }
    @GetMapping("/get/{id:[0-9]+}")
    public JsonResult<BackRoleVO> getRoleById(@PathVariable Long id){
        BackRoleVO backRoleVO = backRoleService.getRoleById(id);
        return JsonResult.ok(backRoleVO);
    }
    @GetMapping("/get/all")
    public JsonResult<PageData<BackRoleListItemVO>> list(@Param("pageNum") Integer pageNum,@Param("pageSize") Integer pageSize){
        PageData<BackRoleListItemVO> list = backRoleService.list(pageNum, pageSize);
        return JsonResult.ok(list);
    }
}
